This repository was archived by the owner on May 15, 2026. It is now read-only.
fix: prevent tool_call_end events for unstarted tool calls - #11093
Draft
ghost wants to merge 1 commit into
Draft
Conversation
This fixes an issue where GLM4.5 and other models get stuck in infinite tool call retry loops when using LM Studio or OpenAI-compatible endpoints. Root cause: processFinishReason() was emitting tool_call_end events for ALL tracked tool calls, even those that never had a tool_call_start emitted (due to missing tool name). This caused finalizeStreamingToolCall to fail silently, resulting in no tool_result being sent to the model. The fix ensures processFinishReason() only emits tool_call_end for tool calls where hasStarted=true, keeping the rawChunkTracker and streamingToolCalls maps synchronized. Also adds diagnostic logging when tool calls are tracked but never started, helping debug malformed tool call patterns from various models.
Author
Review complete. No issues found. The implementation correctly adds a Test coverage is comprehensive with 5 new test cases covering all relevant scenarios. Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
ghost
pushed a commit
that referenced
this pull request
Jan 30, 2026
…1071 This PR combines: 1. PR #11093 fix: NativeToolCallParser processFinishReason hasStarted check 2. GLM model detection utility for LM Studio and OpenAI-compatible providers 3. mergeToolResultText optimization for GLM models 4. Disable parallel_tool_calls for GLM models 5. GLM-4.7 thinking parameter support 6. Diagnostic logging for GLM detection Closes #11071
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11071
Roo Code Task Context (Optional)
N/A
Description
This PR fixes the root cause of GLM4.5 (and other models) getting stuck in infinite file read loops when used via LM Studio or OpenAI-compatible endpoints.
Root Cause Analysis:
The
NativeToolCallParsermaintains two tracking systems:rawChunkTracker- tracks tool calls by stream index as chunks arrivestreamingToolCalls- tracks active tool calls by ID aftertool_call_startis emittedWhen a model sends a tool call ID without a name (common with GLM4.5), the tool call is tracked in
rawChunkTrackerbut never "started" (notool_call_startevent emitted, not added tostreamingToolCalls).The bug was in
processFinishReason(): it emittedtool_call_endfor ALL tracked calls inrawChunkTracker, including those that never hadtool_call_startemitted. This causedfinalizeStreamingToolCall()to fail with "Attempting to finalize unknown tool call" because the call was never instreamingToolCalls.The Fix:
Added a
hasStartedcheck inprocessFinishReason()to only emittool_call_endevents for tool calls that actually had theirtool_call_startevent emitted. Tool calls without names are now skipped with a diagnostic warning.Test Procedure
NativeToolCallParser.spec.ts:tool_call_endis emitted only for started tool callstool_call_endeventsRun tests:
All 17 tests pass.
Pre-Submission Checklist
Screenshots / Videos
N/A - Backend fix, no UI changes.
Documentation Updates
Additional Notes
This fix addresses the symptoms described in issue #11071 where users saw repeated console warnings:
The fix ensures proper synchronization between the dual tracking systems by respecting the
hasStartedflag that indicates whether a tool call lifecycle was properly initiated.Important
Fixes
NativeToolCallParserto preventtool_call_endevents for unstarted tool calls, adding checks and tests for correct behavior.processFinishReason()inNativeToolCallParser.tsto emittool_call_endonly for tool calls withhasStartedtrue.NativeToolCallParser.spec.tsto verify correcttool_call_endemission and logging behavior.This description was created by
for 24e8d92. You can customize this summary. It will automatically update as commits are pushed.